/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package AIproccess;

import Army.building.Building;
import Army.ComputerTeam;
import Army.Group;
import Army.PlayerTeam;
import GameObject.LayerManager;
import java.awt.Point;

/**
 *
 * @author Huy
 */
public class PlayerAIActackNoob extends PlayerAIActack {

	public PlayerAIActackNoob(LayerManager layer, ComputerTeam team) {
		super(layer, team);
	}


	private Group getGroup() {

		int n = RANDOM.nextInt(9);
		if (n >= 6) {
			return team.getArcherGroup();
		} else if (n >= 3) {
			return team.getSwordGroup();
		} else {
			return team.getSpearGroup();
		}

	}

	@Override
	public void proccess() {
		if (targetTeam != null || !targetTeam.isAlive()) {
			getTargetTeam();
		}
		if (team.getCalledBuilding() != null) {
			int x = team.getCalledBuilding().getPosition().x + RANDOM.nextInt(600) - 300;
			int y = team.getCalledBuilding().getPosition().y + RANDOM.nextInt(600) - 300;
			getGroup().setTarget(new Point(x, y));
		} else if (targetTeam != null
				&& (team.getPopulation() - RANDOM.nextInt(5) + 2 > targetTeam.getPopulation()
				|| team.getPopulationLimit() - team.getPopulation() < 5 + RANDOM.nextInt(5))) {
			Building b = targetTeam.getCastle();

			for (int i = 0; i < targetTeam.getListBuilding().size(); i++) {
				Building building = targetTeam.getListBuilding().get(i);
				if (team.getPosition().distance(b.getPosition())
						> team.getPosition().distance(building.getPosition())) {
					b = building;
				}
			}
			getGroup().setTarget(b);
		} else {
			int x = team.getPosition().x + RANDOM.nextInt(600) - 300;
			int y = team.getPosition().y + RANDOM.nextInt(600) - 300;
			getGroup().setTarget(new Point(x, y));
		}

	}
}
